
$(function() {
	//初始化BJUI
	   BJUI.init({
	        JSPATH       : 'B-JUI/',         //[可选]框架路径
	        PLUGINPATH   : 'B-JUI/plugins/', //[可选]插件路径
	        //loginInfo    : {url:'login_timeout.html', title:'登录', width:440, height:240}, // 会话超时后弹出登录对话框
	        statusCode   : {ok:200, error:300, timeout:301}, //[可选]
	        ajaxTimeout  : 300000, //[可选]全局Ajax请求超时时间(毫秒)
	        alertTimeout : 3000,  //[可选]信息提示[info/correct]自动关闭延时(毫秒)
	        pageInfo     : '', //[可选]分页参数
	        keys         : {statusCode:'statusCode', message:'message'}, //[可选]
	        ui           : {
	                         sidenavWidth     : 220,
	                         showSlidebar     : true, //[可选]左侧导航栏锁定/隐藏
	                         overwriteHomeTab : false //[可选]当打开一个未定义id的navtab时，是否可以覆盖主navtab(我的主页)
	                       },
	        debug        : true,    // [可选]调试模式 [true|false，默认false]
	        theme        : 'green' // 若有Cookie['bjui_theme'],优先选择Cookie['bjui_theme']。皮肤[五种皮肤:default, orange, purple, blue, red, green]
	    });  
});

function tohis(){
	alert("存入历史将不可改动",function(){
		$("#time").show();
		$("#sure").show();	
	})
}
function surehis(){
		$("#time").hide();
		$("#sure").hide();	
		var time = $("#time").val();
		if(time==""){
			alert("请选择时间");				
		}else{
			$.ajax({
				type: "GET",
			    url: '../dictdepartment/hashis',
			    data:"time="+time,
			    success: function(r){
			    	if(r.code === 0){
			    		confirm("该月份已有历史，是否要覆盖",function(){
			    			$.ajax({
			    				type: "GET",
			    			    url: '../dictdepartment/tohis',
			    			    data:"time="+time,
			    			    success: function(r){
			    			    	if(r.code === 0){
			    			    		alert("存入成功");
			    			    	}else{
			    				    		alert("存入错误");
			    					}
			    				}
			    			});
			    		});
			    	}else{
			    		$.ajax({
		    				type: "GET",
		    			    url: '../dictdepartment/tohis',
		    			    data:"time="+time,
		    			    success: function(r){
		    			    	if(r.code === 0){
		    			    		alert("存入成功");
		    			    	}else{
		    				    		alert("存入错误");
		    					}
		    				}
		    			});
					}
				}
			});
			
		}	
	
}

function imp(){
	$("#uploadFile").click();
	$("#sureup").show();
}
function up() {
	$("#sureup").hide();
	var uploadFile = document.getElementById("uploadFile").value;      
	if(uploadFile == null || uploadFile == ''){      
		alert("请选择要上传的Excel文件");      
		return;      
	}else{      
		var fileExtend = uploadFile.substring(uploadFile.lastIndexOf('.')).toLowerCase();       
		if(fileExtend == '.xls'||fileExtend == '.xlsx'){    
			    var formData = new FormData();
			    var name = $("#uploadFile").val();
			    formData.append("file",$("#uploadFile")[0].files[0]);
			    formData.append("name","8888888");
			    $.ajax({
			        url : '../dictdepartment/upload',
			        type : 'POST',
			        async : false,
			        data : formData,
			        // 告诉jQuery不要去处理发送的数据
			        processData : false,
			        // 告诉jQuery不要去设置Content-Type请求头
			        contentType : false,
			        beforeSend:function(){
			            console.log("正在进行，请稍候");
			        },
			        success : function(responseStr) {
			            if(responseStr==10){
			                alert("导入成功",function(){
			                	 location.reload();
			                });      
			            }else if(responseStr==20){
			                alert("对不起，请先将当前数据存为历史");
			            }else{
			            	alert("导入失败");
			            }
			        }
			    });
		}else{      
			alert("文件格式需为'.xls'格式");      
			return;      
		}      
	}      
	//提交表单       
}

// 操作列
function datagrid_tree_operation() {
	var html = '<button type="button" class="btn-green" data-toggle="edit.datagrid.tr">编辑</button>'
			+ '<button type="button" class="btn-red"   data-toggle="del.datagrid.tr">禁用</button>'

	return html
}
function zTreeOnClick(event, treeId, treeNode) {
    alert(treeNode.tId + ", " + treeNode.name+":"+treeNode.isParent);
}
function saveData() {
	$('#j_datagrid_tree').datagrid('doSaveEditRow');
}
laydate.render({
	  elem: '#time', //指定元素
	  type: 'month',
	  max:'currentdate'
	});
